package projectodedalo.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import projectodedalo.modelo.RegistroIdea;

/**
 * Servlet implementation class RegistroIdeaServlet
 */
@WebServlet("/RegistroIdeaServlet")
public class RegistroIdeaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistroIdeaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("RegistroIdeaServlet");
		//Lee Datos del JSP para almacenarlo en la BD
		String xtitulo = String.valueOf(request.getParameter("titulo"));
		String xdescripcion = String.valueOf(request.getParameter("descripcion"));
		String xclave1 = String.valueOf(request.getParameter("clave1"));
		String xclave2 = String.valueOf(request.getParameter("clave2"));
		String xclave3 = String.valueOf(request.getParameter("clave3"));
		String xclave4 = String.valueOf(request.getParameter("clave4"));
		
		System.out.println("Datos para la BD");
		System.out.println("Titulo:"+xtitulo+"\nDescripcion:"+xdescripcion+"\nClave1:"+xclave1+"\nClave2:"+xclave2+"\nClave3:"+xclave3+"\nClave4:"+xclave4);
		
		
		RegistroIdea beanRegistroIdea=null;
		ArrayList<RegistroIdea> listado = new ArrayList<RegistroIdea>();
		beanRegistroIdea = new RegistroIdea("1","Titulo 1","Descripcion 1","Palabra Clave 1.1","Palabra Clave 1.2","Palabra Clave 1.3","Palabra Clave 1.4");
		listado.add(beanRegistroIdea);
		beanRegistroIdea = new RegistroIdea("2","Titulo 2","Descripcion 2","Palabra Clave 2.1","Palabra Clave 2.2","Palabra Clave 2.3","Palabra Clave 2.4");
		listado.add(beanRegistroIdea);
		
		request.setAttribute("LISTADO_REGISTRO", listado);
		
		
		
		
		
		
		// Volver a mostrar el JSP
		RequestDispatcher rd = request
				.getRequestDispatcher("registrar_idea.jsp");
		rd.forward(request, response);
		
	}

}
